﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace HQWeb.SysManage.RoleManage
{
    public partial class RoleAddUserTree : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            if (!IsPostBack)
            {
                InitTree();
            }
        }
        #region 部门类型树
        private void InitTree()
        {

            TreeNode node = new TreeNode();
            node.Text = "部门";
            node.Value = "0";
            node.Target = "ShowRoleAddUserList";
            node.Expanded = true;
            node.SelectAction = TreeNodeSelectAction.Expand;
            node.NavigateUrl = "RoleAddUserList.aspx?pid=0";

            IList TreeList = new ArrayList();

            BLL.SysManage.T_PUB_DEPARTMENT DepartBll = new BLL.SysManage.T_PUB_DEPARTMENT();

            TreeList = DepartBll.GetModelList("");
            AddReplies(node, TreeList);
            LeftTree.Nodes.Add(node);
        }
        #endregion

        #region 加载子部门节点
        private void AddReplies(TreeNode node, IList TreeList)
        {
            try
            {
                string strPid = node.Value;

                foreach (Model.SysManage.T_PUB_DEPARTMENT Depart in TreeList)
                {
                    if (Depart.PARENTID.ToString() == strPid)
                    {
                        TreeNode replyNode = new TreeNode();
                        replyNode.Text = Depart.DEPARTMENT_NAME.Trim();
                        replyNode.Value = Depart.DEPARTMENT_ID.ToString();
                        replyNode.NavigateUrl = "RoleAddUserList.aspx?pid=" + replyNode.Value;
                        replyNode.Target = "ShowRoleAddUserList";
                        replyNode.Expanded = false;
                        replyNode.SelectAction = TreeNodeSelectAction.Expand;
                        node.ChildNodes.Add(replyNode);
                        AddReplies(replyNode, TreeList);
                    }

                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
    }
}